package easy;

import java.util.HashMap;
import java.util.Map;

public class Solution_205 {

    public static boolean isIsomorphic(String s, String t) {
        Map<Character, Character> map = new HashMap<>();
        Map<Character, Character> mapReverse = new HashMap<>();
        int length = s.length();
        for (int i = 0; i < length; i++) {
            char one = s.charAt(i);
            char two = t.charAt(i);

            if (!map.containsKey(one)) {
                map.put(one, two);
            }
            if (!mapReverse.containsKey(two)) {
                mapReverse.put(two, one);
            }
            if (!(map.containsKey(one) && map.get(one)==two && mapReverse.containsKey(two) && mapReverse.get(two)==one)) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] a = { };
        System.out.println(isIsomorphic("foo", "bar"));
    }
}
